from models import *
from django.contrib import admin
from django.contrib.admin import ModelAdmin
from django_evolution.models import Version, Evolution
from django.core.cache import cache
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin

admin.site.register(media_type)
admin.site.register(wms_format)

# remove django evolution references from the admin interface
admin.site.unregister(Version)
admin.site.unregister(Evolution)
admin.site.unregister(User)

class UserAdmin(UserAdmin):
    
    class Media:
        css = {
            "all": ("/media/css/admin.css",)
        }

admin.site.register(User, UserAdmin)

class mediaAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ('title', 'type', 'content', 'source', 'latitude', 'longitude', 'date_added', 'date_start', 'date_end', 'themes', 'remote_address', 'owner', 'user_shapes')
        }),
    )
    
    list_display = ('title', 'type', 'source', 'date_start', 'date_end', 'owner', 'user_shapes')

admin.site.register(media, mediaAdmin)

class wms_layerAdmin(admin.ModelAdmin):
    class Media:
      js = ('/media/js/jquery.js','/media/js/wms_admin.js','/media/js/farbtastic.js')
      css = {
          'all': ('/media/css/farbtastic.css',)
      }

    form = wms_layer_form

    # prevent users from delete multiple records
    # (this removes the delete action for more than one selected record)
    actions = None

    fieldsets = (
        (None, {
            'fields': ('title','description','order','style','date_added','date_start','date_end','themes','user_file','label_field_name','label_style')
        }),
        ('Advanced options', {
            'classes': ('collapse',),
            'fields': ('url', 'layers', 'visibility', 'opacity', 'format', 'show_legend', 'tag', 'user_file_type')
        }),
    )

    list_display = ('title','date_start','date_end','order','description','style','label_style')

admin.site.register(wms_layer, wms_layerAdmin)

class wfs_layerAdmin(admin.ModelAdmin):
    class Media:
      js = ('/media/js/jquery.js','/media/js/admin.js','/media/js/farbtastic.js')
      css = {
          'all': ('/media/css/farbtastic.css',)
      }

    fieldsets = (
        (None, {
            'fields': ('title','description','order','url','layers','style','visibility','date_added','date_start','date_end','themes','cluster','tag')
        }),
    )
    
    list_display = ('title','date_start','date_end','order','description','style')

admin.site.register(wfs_layer, wfs_layerAdmin)

class themeAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ('title','description','sub_themes','date_added','date_start','date_end','groups', 'order')
        }),
    )
    
    list_display = ('title','date_start', 'date_end', 'description', 'order')

admin.site.register(theme, themeAdmin)

admin.site.register(place)

class group_attributeAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ('title', 'group', 'domain', 'hide_timeline_default', 
                       'location_western_longitude', 'location_southern_latitude', 'location_eastern_longitude', 'location_northern_latitude', 
                       'show_logo_and_copyright', 'logo_image', 'show_header_animation', 'header_animation_image1', 'header_animation_image2', 'header_animation_image_url', 
                       'online_help_url', 'default_theme', 'about_flat_page', 'intro', 
                       'tour_step1_title','tour_step1_content','tour_step2_title','tour_step2_content','tour_step3_title','tour_step3_content','tour_step4_title','tour_step4_content',
                       'tour_step5_title','tour_step5_content', 'about', 'header_background_color', 'header_link_color', 'contact_us_email','google_analytics_id')
        }),
    )
    
    list_display = ('title', 'group', 'domain', 'header_background_color', 'header_link_color', 'contact_us_email')

admin.site.register(group_attribute, group_attributeAdmin)

class UserUploadedShapesAdmin(admin.ModelAdmin):

    def __init__(self,*args,**kwargs):
        cache.delete('user_uploaded_shapes')
        super(UserUploadedShapesAdmin, self).__init__(*args,**kwargs)

    class Media:
      js = ('/media/js/jquery.js','/media/js/admin.js','/media/js/farbtastic.js')
      css = {
          'all': ('/media/css/farbtastic.css',)
      }

    fieldsets = (
        (None, {
            'fields': ('style', 'geoms', 'attributes')
        }),
    )
    
    list_display = ('id', 'style',)

admin.site.register(UserUploadedShapes, UserUploadedShapesAdmin)

